home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17474 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  50 lines

  1. Path: alterdial.uu.net!not-for-mail
  2. From: jim@dataware.com
  3. Newsgroups: comp.lang.c++
  4. Subject: VC++ 4: Templates and exported DLL functions
  5. Date: 16 Apr 1996 03:09:43 GMT
  6. Organization: Dataware Technologies, Inc.
  7. Message-ID: <4kv31n$ca6@alterdial.UU.NET>
  8. NNTP-Posting-Host: gw.dataware.com
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=US-ASCII
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13. There seems to be a logical hole in the way that Visual C++ uses a storage 
  14. class-like extension to indicate that a class in a DLL is to be exported to 
  15. clients of the DLL.
  16.  
  17. For a non-template class, one simply inserts the extension keyword into the 
  18. class definition:
  19.  
  20.     class __declspec(dllexport) AIntClass2
  21.         {
  22.         int AFunc();
  23.         };
  24.  
  25.     int AIntClass2::AFunc(){return 0;}
  26.  
  27. This results in the entire class being exported.
  28. I don't see how to accomplish the same thing with a template class. E.g.:
  29.  
  30.     template <class T>
  31.     class AClass
  32.         {
  33.         T AFunc();
  34.         };
  35.  
  36.     int AClass<int>::AFunc(){return 0;}
  37.  
  38. The __declspec(dllexport) modifier cannot be added to the template declaration 
  39. (syntax error). It can be added to AFunc(), but that only exports the single 
  40. function, not the whole class. I tried using a typedef
  41.  
  42.     typedef AClass<int> __declspec(dllexport) AClassInt1;
  43.  
  44. but since the __declspec(dllexport) is a storage modifier, it is not 
  45. considered part of the type and so uses of the typedef tag are not exported.
  46.  
  47. Is there a solution I'm missing here? (aside from listing every identifier 
  48. explicitly in a .DEF file)?
  49.  
  50.